﻿/*******************************************************************************************************************************************
Modification History:
********************************************************************************************************************************************
Date		Author		    Description
********************************************************************************************************************************************
06/07/2011	Brian Kuhn	    Created Guard class
*******************************************************************************************************************************************/
using System;
using System.Globalization;

namespace Concise
{
    /// <summary>
    /// Provides a set of static methods that guard against or assert that an assertion has been met. 
    /// This class cannot be inherited.
    /// </summary>
    public static class Guard
    {
        //=======================================================================================================
        //  Public Methods
        //=======================================================================================================
        #region Against<TException>(bool Verifyion, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the <paramref name="Verifyion"/> statement is <see langword="true" />.
        /// </summary>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="Verifyion">The Verifyion to evaluate. If <see langword="true" /> then an exception of type <typeparamref name="TException"/> is thrown.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void Against<TException>(bool Verifyion, string message) where TException : Exception
        {
            if (Verifyion)
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region Against<TException>(Func<bool> Verifyion, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the <paramref name="Verifyion"/> statement evalutes as <see langword="true" />.
        /// </summary>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="Verifyion">The Verifyion to evaluate. If <see langword="true" /> then an exception of type <typeparamref name="TException"/> is thrown.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void Against<TException>(Func<bool> Verifyion, string message) where TException : Exception
        {
            if (Verifyion())
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region AgainstEmptyString(string value, string name)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not an empty string.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is an <see cref="String.Empty"/> string, 
        /// an <see cref="ArgumentNullException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstEmptyString(string value, string name)
        {
            if (String.Compare(value, String.Empty, StringComparison.Ordinal) == 0)
            {
                throw new ArgumentNullException(name);
            }
        }
        #endregion

        #region AgainstGreaterThan(int value, string name, int maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not greater than the specified maximum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="maximum">The maximum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstGreaterThan(int value, string name, int maximum)
        {
            if (value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstGreaterThan(long value, string name, long maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not greater than the specified maximum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="maximum">The maximum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstGreaterThan(long value, string name, long maximum)
        {
            if (value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstGreaterThan(float value, string name, float maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not greater than the specified maximum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="maximum">The maximum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstGreaterThan(float value, string name, float maximum)
        {
            if (value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstGreaterThan(decimal value, string name, decimal maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not greater than the specified maximum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="maximum">The maximum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstGreaterThan(decimal value, string name, decimal maximum)
        {
            if (value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstGreaterThan(double value, string name, double maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not greater than the specified maximum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="maximum">The maximum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstGreaterThan(double value, string name, double maximum)
        {
            if (value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstLessThan(int value, string name, int minimum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not less than the specified minimum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstLessThan(int value, string name, int minimum)
        {
            if (value < minimum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstLessThan(long value, string name, long minimum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not less than the specified minimum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstLessThan(long value, string name, long minimum)
        {
            if (value < minimum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstLessThan(float value, string name, float minimum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not less than the specified minimum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstLessThan(float value, string name, float minimum)
        {
            if (value < minimum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstLessThan(decimal value, string name, decimal minimum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not less than the specified minimum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstLessThan(decimal value, string name, decimal minimum)
        {
            if (value < minimum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstLessThan(double value, string name, double minimum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not less than the specified minimum.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstLessThan(double value, string name, double minimum)
        {
            if (value < minimum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstNullOrEmptyString(string value, string name)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not a null reference or an empty string.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is a <see langword="null"/> reference or an empty string, 
        /// an <see cref="ArgumentNullException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstNullOrEmptyString(string value, string name)
        {
            if (String.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(name);
            }
        }
        #endregion

        #region AgainstNullReference(object value, string name)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is not a null reference.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is a <see langword="null"/> reference, 
        /// an <see cref="ArgumentNullException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstNullReference(object value, string name)
        {
            if (value == null)
            {
                throw new ArgumentNullException(name);
            }
        }
        #endregion

        #region AgainstOutOfRange(int value, string name, int minimum, int maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is within the specified range.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value of the range.</param>
        /// <param name="maximum">The maximum acceptable value of the range.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/> 
        /// <u>or</u> <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstOutOfRange(int value, string name, int minimum, int maximum)
        {
            if (value < minimum || value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstOutOfRange(long value, string name, long minimum, long maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is within the specified range.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value of the range.</param>
        /// <param name="maximum">The maximum acceptable value of the range.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/> 
        /// <u>or</u> <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstOutOfRange(long value, string name, long minimum, long maximum)
        {
            if (value < minimum || value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstOutOfRange(float value, string name, float minimum, float maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is within the specified range.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value of the range.</param>
        /// <param name="maximum">The maximum acceptable value of the range.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/> 
        /// <u>or</u> <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstOutOfRange(float value, string name, float minimum, float maximum)
        {
            if (value < minimum || value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstOutOfRange(decimal value, string name, decimal minimum, decimal maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is within the specified range.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value of the range.</param>
        /// <param name="maximum">The maximum acceptable value of the range.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/> 
        /// <u>or</u> <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstOutOfRange(decimal value, string name, decimal minimum, decimal maximum)
        {
            if (value < minimum || value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region AgainstOutOfRange(double value, string name, double minimum, double maximum)
        /// <summary>
        /// Validates that the supplied <paramref name="value"/> is within the specified range.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <param name="minimum">The minimum acceptable value of the range.</param>
        /// <param name="maximum">The maximum acceptable value of the range.</param>
        /// <remarks>
        /// If the <paramref name="value"/> is <b>less than</b> the specified <paramref name="minimum"/> 
        /// <u>or</u> <b>greater than</b> the specified <paramref name="maximum"/>, 
        /// an <see cref="ArgumentOutOfRangeException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void AgainstOutOfRange(double value, string name, double minimum, double maximum)
        {
            if (value < minimum || value > maximum)
            {
                throw new ArgumentOutOfRangeException(name);
            }
        }
        #endregion

        #region VerifyAreEqual<TException>(object first, object second, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the an instance of an object is not equal to another object instance.
        /// </summary>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="first">The object instance to compare.</param>
        /// <param name="second">The object instance to compare with.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyAreEqual<TException>(object first, object second, string message) where TException : Exception
        {
            if (first != second)
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region VerifyAreNotEqual<TException>(object first, object second, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the an instance of an object is equal to another object instance.
        /// </summary>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="first">The object instance to compare.</param>
        /// <param name="second">The object instance to compare with.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyAreNotEqual<TException>(object first, object second, string message) where TException : Exception
        {
            if (first == second)
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region VerifyImplements<TInterface>(object instance, string message)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the specified object 
        /// <paramref name="instance"/> does not implement the <typeparamref name="TInterface"/> interface.
        /// </summary>
        /// <typeparam name="TInterface">The interface type the object <paramref name="instance"/> must implement.</typeparam>
        /// <param name="instance">The object insance to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyImplements<TInterface>(object instance, string message)
        {
            Guard.VerifyImplements<TInterface>(instance.GetType(), message);
        }
        #endregion

        #region VerifyImplements<TInterface>(Type type, string message)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the specified <paramref name="type"/> 
        /// does not implement the <typeparamref name="TInterface"/> interface.
        /// </summary>
        /// <typeparam name="TInterface">The interface type the <paramref name="type"/> must implement.</typeparam>
        /// <param name="type">The <see cref="Type"/> to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyImplements<TInterface>(Type type, string message)
        {
            Guard.VerifyImplements<TInterface, ArgumentException>(type, message);
        }
        #endregion

        #region VerifyImplements<TInterface, TException>(Type type, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the specified <paramref name="type"/> does not implement the <typeparamref name="TInterface"/> interface.
        /// </summary>
        /// <typeparam name="TInterface">The interface type the <paramref name="type"/> must implement.</typeparam>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="type">The <see cref="Type"/> to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyImplements<TInterface, TException>(Type type, string message) where TException : Exception
        {
            if (!typeof(TInterface).IsAssignableFrom(type))
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region VerifyInheritsFrom<TBase>(object instance, string message)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the specified object 
        /// <paramref name="instance"/> does not inherit from <typeparamref name="TBase"/> type.
        /// </summary>
        /// <typeparam name="TBase">The base type the <paramref name="instance"/> must inherit from.</typeparam>
        /// <param name="instance">The object instance to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyInheritsFrom<TBase>(object instance, string message) where TBase : Type
        {
            Guard.VerifyInheritsFrom<TBase>(instance.GetType(), message);
        }
        #endregion

        #region VerifyInheritsFrom<TBase>(Type type, string message)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the specified <paramref name="type"/> 
        /// does not inherit from <typeparamref name="TBase"/> type.
        /// </summary>
        /// <typeparam name="TBase">The base type the <paramref name="type"/> must inherit from.</typeparam>
        /// <param name="type">The <see cref="Type"/> to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyInheritsFrom<TBase>(Type type, string message)
        {
            Guard.VerifyInheritsFrom<TBase, ArgumentException>(type, message);
        }
        #endregion

        #region VerifyInheritsFrom<TBase, TException>(Type type, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the specified <paramref name="type"/> does not inherit from <typeparamref name="TBase"/> type.
        /// </summary>
        /// <typeparam name="TBase">The base type the <paramref name="type"/> must inherit from.</typeparam>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="type">The <see cref="Type"/> to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyInheritsFrom<TBase, TException>(Type type, string message) where TException : Exception
        {
            if (type.BaseType != typeof(TBase))
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region VerifyIsTypeOf<TType>(object instance, string message)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the specified object <paramref name="instance"/> 
        /// is not of the specified <typeparamref name="TType"/> type.
        /// </summary>
        /// <typeparam name="TType">The <see cref="Type"/> that the object <paramref name="instance"/> is expected to be.</typeparam>
        /// <param name="instance">The object instance to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyIsTypeOf<TType>(object instance, string message)
        {
            Guard.VerifyIsTypeOf<TType, ArgumentException>(instance, message);
        }
        #endregion

        #region VerifyIsTypeOf<TType, TException>(object instance, string message)
        /// <summary>
        /// Raises an exception of type <typeparamref name="TException"/> using the specified <paramref name="message"/> 
        /// when the specified object <paramref name="instance"/> is not of the specified <typeparamref name="TType"/> type.
        /// </summary>
        /// <typeparam name="TType">The <see cref="Type"/> that the object <paramref name="instance"/> is expected to be.</typeparam>
        /// <typeparam name="TException">The type of exception to raise.</typeparam>
        /// <param name="instance">The object instance to validate.</param>
        /// <param name="message">The message that describes the error.</param>
        public static void VerifyIsTypeOf<TType, TException>(object instance, string message) where TException : Exception
        {
            if (!(instance is TType))
            {
                throw (TException)Activator.CreateInstance(typeof(TException), message);
            }
        }
        #endregion

        #region VerifyIsUtcDateTime(DateTime value, string name)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the supplied <paramref name="value"/> 
        /// is a <see cref="DateTime"/> whose <see cref="DateTime.Kind"/> is <see cref="DateTimeKind.Utc"/>.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <remarks>
        /// If the <see cref="DateTime.Kind"/> of the <paramref name="value"/> is <b>not</b> <see cref="DateTimeKind.Utc"/>, 
        /// an <see cref="ArgumentException"/> is raised using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void VerifyIsUtcDateTime(DateTime value, string name)
        {
            if (value.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentException(String.Format(null, "{0} is not represented as Coordinated Universal Time (UTC).", value.ToString(DateTimeFormatInfo.InvariantInfo.UniversalSortableDateTimePattern, DateTimeFormatInfo.InvariantInfo)), name);
            }
        }
        #endregion

        #region VerifyIsUtcDateTime(DateTime? value, string name)
        /// <summary>
        /// Raises an <see cref="ArgumentException"/> when the supplied <paramref name="value"/> 
        /// is a <see cref="DateTime"/> whose <see cref="DateTime.Kind"/> is <see cref="DateTimeKind.Utc"/>.
        /// </summary>
        /// <param name="value">The value of the method argument to validate.</param>
        /// <param name="name">The name of the method argument.</param>
        /// <remarks>
        /// If the <paramref name="value"/> has been assigned a value whose <see cref="DateTime.Kind"/> 
        /// is <b>not</b> <see cref="DateTimeKind.Utc"/>, an <see cref="ArgumentException"/> is raised 
        /// using the supplied <paramref name="name"/>.
        /// </remarks>
        public static void VerifyIsUtcDateTime(DateTime? value, string name)
        {
            if (value.HasValue && value.Value.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentException(String.Format(null, "{0} is not represented as Coordinated Universal Time (UTC).", value.Value.ToString(DateTimeFormatInfo.InvariantInfo.UniversalSortableDateTimePattern, DateTimeFormatInfo.InvariantInfo)), name);
            }
        }
        #endregion
    }
}
